livepatch: ARM/x86: Check displacement of old_addr and new_addr
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 19 Sep 2016 16:37:50 +0000 (12:37 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 28 Sep 2016 02:06:10 +0000 (22:06 -0400)
commit84eabb2754b3059cfb19b5ec801462324430f26a
tree861e0b139b812e50ad2bd5b080239ca689dc284e
parent0d35756e4cb952394248b2932b28de12a3e3a240
livepatch: ARM/x86: Check displacement of old_addr and new_addr

If the distance is too big we are in trouble - as our relocation
distance can surely be clipped, or still have a valid width - but
cause an overflow of distance.

On various architectures the maximum displacement for a unconditional
branch/jump varies. ARM32 is +/- 32MB, ARM64 is +/- 128MB while x86
for 32-bit relocations is +/- 2G.

Note: On x86 we could use the 64-bit jmpq instruction which
would provide much bigger displacement to do a jump, but we would
still have issues with the new function not being able to reach
any of the old functions (as all the relocations would assume 32-bit
displacement). And "furthermore would require an register or
memory location to load/store the address to." (From Jan).

On ARM the conditional branch supports even a smaller displacement
but fortunately we are not using that.

Reviewed-by: Julien Grall <julien.grall@arm.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
docs/misc/livepatch.markdown
xen/arch/arm/arm64/livepatch.c
xen/common/livepatch.c
xen/include/asm-arm/livepatch.h
xen/include/asm-x86/livepatch.h
xen/include/xen/livepatch.h